//引入插件基类

import plugin from '../../../lib/plugins/plugin.js';

//引入fetch

import fetch from 'node-fetch'

//导出类,继承插件基类

export class Qb extends plugin {

  constructor() {
    super({
      //插件配置

      name: 'Qb',
      dsc: 'QQ绑定手机号查询',
      event: 'message',
      priority: 5000,

      rule: [
        {
          reg: '^#?(查绑)(.*)',
          fnc: 'cqb'
        }
      ]
    });
  }

  //处理函数

  async cqb(e) {
    let msg = e.msg;
    let qq = msg.replace(/#|查绑/g, "").trim();

    let url = `https://zy.xywlapi.cc/qqapi?qq=${qq}`;

    let res = await fetch(url).catch(err => logger.error(err));
    res = await res.json();

    let replyMsg;
    if (res.message === '查询成功') {
      replyMsg = `查询成功!\n号码:${res.phone}\n地区:${res.phonediqu}`
    } else if (res.message === '没有找到') {
      replyMsg = `暂无此人数据`
    }

    await this.reply(replyMsg, true, { recallMsg: 30 });
  }

}